import { request } from '@/utils/request'

/**
 * 用户登录
 */
export function login(data) {
  return request.post('/auth/login', {
    identifier: data.username,
    password: data.password,
    remember: data.remember || false
  })
}

/**
 * 用户退出
 */
export function logout() {
  return request.post('/auth/logout')
}

/**
 * 获取用户信息
 */
export function getUserInfo() {
  return request.get('/auth/me')
}

/**
 * 刷新token
 */
export function refreshToken() {
  return request.post('/auth/refresh')
}

/**
 * 修改密码
 */
export function changePassword(data) {
  return request.post('/auth/change-password', {
    oldPassword: data.oldPassword,
    newPassword: data.newPassword,
    confirmPassword: data.confirmPassword
  })
}

/**
 * 重置密码
 */
export function resetPassword(data) {
  return request.post('/auth/reset-password', {
    email: data.email
  })
}

/**
 * 验证token有效性
 */
export function validateToken() {
  return request.get('/auth/validate')
}